﻿using MvcWechat.Models;
using MvcWechat.Services;
using System.Web.Mvc;

namespace MvcWechat.Areas.Manager.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Manager/Login/

        public ActionResult Index()
        {
            return View();
        }

        string code = string.Empty;
        public ActionResult GetImg()
        {
            int width = 100; //图片宽
            int height = 50; //图片高
            int fontsize = 40;  //字体 
            byte[] bytes = ValidateCode.CreateValidateGraphic(out code, 4, width, height, fontsize);
            Session["VilidateCode"] = code; 
            return File(bytes, @"image/jpeg");
        }
        public string GetCode()
        {
            return Session["VilidateCode"].ToString();
        }
       
        [HttpPost]
        public JsonResult Login(UserInfo user)
        {
            if (user.Name == "admin" && user.Pwd == "admin123")
            {
                Session["UserName"] = "admin";
                return Json(1);
            }
            else
            {
                return Json(0);
            }
        }
    }
}
